package com.lin.mr.maizilaundry.utils;

import android.content.Context;
import android.content.SharedPreferences.Editor;


/**
 * Created by lenovog on 2016/8/28.
 */
public class ShareUtils {
    public static final String INFO_TYPE = "UserInfo";
    public static final String FLOAT_IMAGE = "FloatImage";
    public static final String CONTACTS_INFO = "CONTACTS_INFO";
    public static final String ISFIRSTTIME = "isFirstTime";


    /**
     * 处理用户列表中的缓存信息
     * @param context
     * @param json
     */
    public static void putContactInfo(Context context,String json){
        Editor editor = context.getSharedPreferences(CONTACTS_INFO,Context.MODE_PRIVATE).edit();
        editor.putString("contacts_info",json);
        editor.commit();
    }

    public static String getContactsInfo(Context context){
        return context.getSharedPreferences(CONTACTS_INFO,Context.MODE_PRIVATE).getString("contacts_info","");
    }

    /**
     *存入用户信息
     */
    //用户名字
    public static void putName(Context context,String name){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.putString("name",name);
        editor.commit();
    }

    //手机号码
    public static void putNumber(Context context,String number){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.putString("phoneNumber",number);
        editor.commit();
    }

    //性别
    public static void putGender(Context context,String gender){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.putString("gender",gender);
        editor.commit();
    }

    //城市
    public static void putCity(Context context,String city){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.putString("city",city);
        editor.commit();
    }

    //地址
    public static void putAddress(Context context,String address){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.putString("address",address);
        editor.commit();
    }
    /**
     * 读取数据
     */
    //获取用户名
    public static String getName(Context context){
        return context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).getString("name","");
    }

    //获取手机号码
    public static String getNumber(Context context){
        return context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).getString("phoneNumber","");
    }

    //获取性别
    public static String getGender(Context context){
        return context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).getString("gender","");
    }

    //获取城市
    public static String getCity(Context context){
        return context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).getString("city","");
    }

    //获取地址
    public static String getAddress(Context context){
        return context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).getString("address","");
    }

    /**
     * 移除用户信息
     */
    public static void removeName(Context context){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.remove("name");
        editor.commit();
    }

    public static void removeNumber(Context context){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.remove("phoneNumber");
        editor.commit();
    }


    public static void removeGender(Context context){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.remove("gender");
        editor.commit();
    }

    public static void removeCity(Context context){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.remove("city");
        editor.commit();
    }
    public static void removeAddress(Context context){
        Editor editor = context.getSharedPreferences(INFO_TYPE,Context.MODE_PRIVATE).edit();
        editor.remove("address");
        editor.commit();
    }

    /**
     * 件洗页面的悬浮按钮的距离
     */
    public static void putLeft(Context context,int left){
        Editor editor = context.getSharedPreferences(FLOAT_IMAGE,Context.MODE_PRIVATE).edit();
        editor.putInt("left",left);
        editor.commit();
    }

    public static void putTop(Context context,int top){
        Editor editor = context.getSharedPreferences(FLOAT_IMAGE,Context.MODE_PRIVATE).edit();
        editor.putInt("top",top);
        editor.commit();
    }

    /**
     * 获取悬浮按钮到屏幕的上下距离
     * @param context
     * @return
     */
    public static int getLeft(Context context){
        return context.getSharedPreferences(FLOAT_IMAGE,Context.MODE_PRIVATE).getInt("left",0);
    }

    public static int getTop(Context context){
        return context.getSharedPreferences(FLOAT_IMAGE,Context.MODE_PRIVATE).getInt("top",0);
    }

    /**
     * 判断引导页是否是第一次打开
     */
    public static void putFirstTime(Context context,boolean isFirst){
        Editor editor = context.getSharedPreferences(ISFIRSTTIME,Context.MODE_PRIVATE).edit();
        editor.putBoolean(ISFIRSTTIME,isFirst);
        editor.commit();
    }

    public static boolean getFirstTime(Context context){
        return context.getSharedPreferences(ISFIRSTTIME,Context.MODE_PRIVATE).getBoolean(ISFIRSTTIME,false);
    }

}
